package cn.woochen.comlib.util.ext

import android.annotation.SuppressLint
import android.view.View
import com.jakewharton.rxbinding4.view.clicks
import cn.woochen.comlib.util.OnSingleClickListener
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import java.util.concurrent.TimeUnit

@SuppressLint("CheckResult")
fun View.setOnSingleClickListener(timeSecond:Long = 1,singleEvent: (View)->Any?){
    this.clicks()
        .subscribeOn(AndroidSchedulers.mainThread())
        .throttleFirst(timeSecond, TimeUnit.SECONDS)
        .subscribe {
            singleEvent.invoke(this)
        }
}

fun View.setOnSingleClickListener(singleEvent: OnSingleClickListener?, timeSecond:Long = 1){
    this.clicks()
        .subscribeOn(AndroidSchedulers.mainThread())
        .throttleFirst(timeSecond, TimeUnit.SECONDS)
        .subscribe {
            singleEvent?.onSingleClick(this)
        }
}
